package emulator.unittest.hardware.nmos6502.commands;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import emulator.EmulatorException;
import emulator.hardware.HwWord;
import emulator.hardware.nmos6502.Command;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.hardware.nmos6502.Flags6502;
import emulator.unittest.hardware.nmos6502.MockOperand;

public class BranchTestBase {

	protected Command branch_command;
	protected int bit;
	protected boolean value;

	public BranchTestBase() {
		super();
	}

	@Test
	public void testBranchNot() throws EmulatorException {
		if (branch_command != null)
		{
			Cpu6502 cpu = new Cpu6502();
			cpu.setPC(0);
			Flags6502 flags = cpu.getFlags();
			flags.setBit(bit, !value);
			cpu.setFlags(flags);
			branch_command.execute(cpu, new MockOperand(0x3F));
			assertEquals(new HwWord(0), cpu.getPC());
		}
	}

	@Test
	public void testBranchForward() throws EmulatorException {
		if (branch_command != null)
		{
			Cpu6502 cpu = new Cpu6502();
			cpu.setPC(0);
			Flags6502 flags = cpu.getFlags();
			flags.setBit(bit, value);
			cpu.setFlags(flags);
			branch_command.execute(cpu, new MockOperand(0x3F));
			assertEquals(new HwWord(0x3F), cpu.getPC());
		}
	}

	@Test
	public void testBranchBackwards() throws EmulatorException {
		if (branch_command != null)
		{
			Cpu6502 cpu = new Cpu6502();
			cpu.setPC(0x1FF);
			Flags6502 flags = cpu.getFlags();
			flags.setBit(bit, value);
			cpu.setFlags(flags);
			branch_command.execute(cpu, new MockOperand(0xFE));
			assertEquals(new HwWord(0x1FD), cpu.getPC());
		}
	}

}